//
//  BaseViewController.swift
//  LPSina
//
//  Created by apple on 16/3/23.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {
    
    // MARK:- 类属性-----------------------------
    //记录当前的登录状态
    var islogin: Bool = true

    var visitorView : VisitorView?
    
    // MARK:- 系统方法回调-----------------------------
    override func loadView() {
        
         islogin ? super.loadView() : setupVisitorView()
        
    }
    
    
    // MARK:- 自定义函数法-----------------------------
    func setupVisitorView()  {
        // 1，创建访客视图
        let visitorView = VisitorView.visitor()
        
        // 2，监听按钮的点击
        visitorView.registerBtn.addTarget(self, action: "registerBtnClick", forControlEvents: .TouchUpInside)
        visitorView.loginBtn.addTarget(self, action: "loginBtnClick", forControlEvents: .TouchUpInside)
        
        // 3，设置NavigationBar两边的item
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Done, target: self, action: "registerBtnClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Done, target: self, action: "loginBtnClick")
        
        // 4，访问访客视图
        self.visitorView = visitorView
        view = visitorView

    }
    
    func setupVisitorViewInfo(text: String , imageName: String) {
        
        visitorView?.textLabel.text = text
        visitorView?.iconImageView.image = UIImage(named: imageName)
        visitorView?.rotationImageView.hidden = true
    }
    
    // 添加动画的方法
    func setupRotationView() {
    
        // 1，创建一个基本动画
        let rotationAnim = CABasicAnimation(keyPath: "transform.rotation.z")
        
        // 2，设置动画的参数
        rotationAnim.fromValue = 0.0
        rotationAnim.toValue = M_PI * 2
        rotationAnim.repeatCount = MAXFLOAT
        rotationAnim.duration = 10.0
        rotationAnim.removedOnCompletion = false //切换界面回来动画依然有效
        
        // 3，添加动画
        visitorView?.rotationImageView.layer.addAnimation(rotationAnim, forKey: nil)
    }
    
    // 事件监听方法
    func registerBtnClick() {
        print("点击了注册按钮")
    }
    
    func loginBtnClick() {
        print("点击了登录按钮")
    }
    
}
